doctype html
html.playbody
  head
    meta(charset="utf-8")
    meta(name="viewport",content="width=device-width, initial-scale=1, maximum-scale=1")
    meta(http-equiv="X-UA-Compatible",content="IE=edge, chrome=1")
    meta(name="renderer",content="webkit")
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    link(rel="stylesheet", href='https://cdn.jsdelivr.net/npm/p2p-dplayer@latest/dist/DPlayer.min.css')
  body.playbody
    if !phoneviewer||!waplock
      #player
      p.level #{level}
      - var logo = player.mark || '';
      if !player.kaiguan
        - logo = '';
      if player.wenzikaiguan
        - var bold = player.bold == 'on'? "bold":"normal";
        - var italic = player.italic == 'on'? "italic":"normal";
        - var underline = player.underline == 'on'?"underline":"none";
        - var wenzix = player.wenzix + "px";
        - var wenziy = player.wenziy + "px";
        - var opacity = player.opacity;
        - var font = player.font;
        - var fontsize = player.fontsize + 'px';
        - var color = player.color;
        - var wenziposition = player.wenziposition;
        - var style = '';
        case wenziposition
          when "lefttop"
            - style = {left:wenzix,top:wenziy,right:'auto',bottom:'auto'};
          when "leftbottom"
            - style = {left:wenzix,top:'auto',right:'auto',bottom:wenziy};
          when "righttop"
            - style = {left:'auto',top:wenziy,right:wenzix,bottom:'auto'};
          when "rightbottom"
            - style = {left:'auto',top:'auto',right:wenzix,bottom:wenziy};
        .adwrap
          .wenziad(style=style)
            a(href="#{player.link}" target="_blank") #{player.text}
        style.
          .wenziad{
            padding:5px;
            z-index:1000;
            position:fixed;
            background: #{rgba};
          }
          .wenziad a{
            font-family:"#{font}",sans-serif;
            font-size:#{fontsize};
            font-weight:#{bold};
            font-style:#{italic};
            opacity:#{opacity};
            color: #{color};
            text-decoration: #{underline};
          }
      script(src="/javascripts/fixie.js")
      script(src="https://cdn.jsdelivr.net/npm/cdnbye@latest")
      script(src="https://cdn.jsdelivr.net/npm/p2p-dplayer@latest")
      script(src="/javascripts/jquery.min.js")
      script(src="/layer/layer.js")
      .hidden!=player.tongji
      - var theposter;
      if poster
        - theposter = poster;
      else
        - theposter = "/videos/"+id+"/1.jpg";
      script.
        function getParentUrl() {   
          var url = null;  
          if (parent !== window) {   
              try {  
                  url = parent.location.href;   
              }catch (e) {   
                  url = document.referrer;   
              }   
            }  
            return url;  
        }
        var parenturl = getParentUrl();
        if(!parenturl) {
          parenturl = (window.location != window.parent.location)?document.referrer:document.location;
        }
        var antiurl = "#{antiurl}";
        var categoryantiurl = "#{categoryanti}";
        var antiarr = antiurl.split(",");
        var open = "#{open}";
        var categoryantiarr = categoryantiurl.split("|");
        var anti= false;
        var level = $(".level").text();
        var token = "#{token}";
        var m3u8 = '/videos/#{id}/index.m3u8';
        if(token!=''){
          m3u8 = m3u8+'?token='+token;
        } 
        if(open=="on"){
          anti = false;
        } else {
          if(categoryantiurl!="") {
            if(parenturl== null) {
              anti = true;
            } else {
              for(var i=0;i<categoryantiarr.length;i++) {
                if(parenturl.indexOf(categoryantiarr[i])==0) {
                  anti = false;
                  break;
                } else {
                  anti = true;
                }
              }
            }
          } else {
            if(antiurl != ""){
              if(parenturl == null) {
                anti = true;
              } else {
                for(var i=0;i<antiarr.length;i++) {
                  if(parenturl.indexOf(antiarr[i])==0) {
                    anti = false;
                    break;
                  } else {
                    anti = true;
                  }
                }
              }
            }
          }
        }
        if(!anti){
          var dp = new DPlayer({
              container: document.getElementById('player'),
              screenshot: true,
              lang:  'zh-cn',
              autoplay: false,
              logo: '#{logo}',
              mutex: true,
              video: {
                  url: m3u8,
                  pic: '#{theposter}',
                  thumbnails: '/videos/#{id}/thumbnails.jpg',
                  type: 'hls'
              },
              hlsjsConfig: {
                  debug: false,
                  // Other hlsjsConfig options provided by hls.js
                  p2pConfig: {
                      logLevel: false,
                      // Other p2pConfig options provided by CDNBye
                  }
              },
              subtitle: {
                  url: '/videos/#{id}/1.vtt',
                  fontSize: '25px',
                  bottom: '10%'
              },
              contextmenu: [{
                  text: '云转码express-ffmpeg',
                  link: 'http://ffmpeg.moejj.com/'
              },
              {
                  text: '萌JJ博客',
                  link: 'https://moejj.com/'
              }]
          });
          var ad = $(".adwrap").html();
          dp.on('canplay',function () {
            $(".dplayer-video-wrap").find(".wenziad").remove();
            $(".dplayer-video-wrap").append(ad);
            $(".adwrap").remove();
            $(".dplayer-video").attr("x5-video-player-type","h5");
            $(".dplayer-video").attr("x5-video-orientation","landscape");
            $(".dplayer-video").attr("x5-video-player-fullscreen","true");
          });
          dp.on('ended', function() {
            if(level=="0") {
              layer.msg('想要继续观看，请注册账号');
            } else if(level=='1') {
              layer.msg('想要继续观看，请开通会员');
            }
          });
        } else {
          layer.msg('无权播放此视频，将在5秒后将进行跳转');
          setTimeout(function(){
              window.location="#{antiredirect}";
            },5000)
        }
      if player.kaiguan
        - var markx = player.markx + "px";
        - var marky = player.marky + "px";
        case player.position
          when 'lefttop'
            style.
              .dplayer-logo {
                  pointer-events: none;
                  position: absolute;
                  right:auto;
                  left: #{markx};
                  top: #{marky};
                  bottom: auto;
                  max-width: 200px;
                  max-height: 50px;
              }
          when 'leftbottom'
            style.
              .dplayer-logo {
                  pointer-events: none;
                  position: absolute;
                  right:auto;
                  left: #{markx};
                  top: auto;
                  bottom: #{marky};
                  max-width: 200px;
                  max-height: 50px;
              }
          when 'righttop'
            style.
              .dplayer-logo {
                  pointer-events: none;
                  position: absolute;
                  right:#{markx};
                  left: auto;
                  top: #{marky};
                  bottom: auto;
                  max-width: 200px;
                  max-height: 50px;
              }
          when 'rightbottom'
            style.
              .dplayer-logo {
                  pointer-events: none;
                  position: absolute;
                  right:#{markx};
                  left: auto;
                  top: auto;
                  bottom: #{marky};
                  max-width: 200px;
                  max-height: 50px;
              }
      if player.p2p != 'on'
        style.
          #p2pserver{
            display:none;
          }
    else if phoneviewer&&waplock
      #locktip
        p!=player.locktip